import * as setupAxiosConfig from '@/shared/config/axios-interceptor';
import { SERVER_API_URL } from '@/constants';

describe('Axios interceptor', () => {
  it('should use localStorage to provide bearer', () => {
    <%_ if (authenticationType === 'jwt') { _%>
    localStorage.setItem('<%=jhiPrefixDashed %>-authenticationToken', 'auth');
    <%_ } _%>
    const result = setupAxiosConfig.onRequestSuccess(() => console.log('A problem occured'));

    <%_ if (authenticationType === 'jwt') { _%>
    expect(result.headers.Authorization).toBe('Bearer auth');
    <%_ } _%>
    expect(result.url.indexOf(SERVER_API_URL)).toBeGreaterThan(-1);
  });

  it('should use sessionStorage to provide bearer', () => {
    <%_ if (authenticationType === 'jwt') { _%>
    sessionStorage.setItem('<%=jhiPrefixDashed %>-authenticationToken', 'auth');
    <%_ } _%>
    const result = setupAxiosConfig.onRequestSuccess(() => console.log('A problem occured'));

    <%_ if (authenticationType === 'jwt') { _%>
    expect(result.headers.Authorization).toBe('Bearer auth');
    <%_ } _%>
    expect(result.url.indexOf(SERVER_API_URL)).toBeGreaterThan(-1);
  });
});
